package com.netty.base;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author Wang Chen Peng
 * @date 2018/12/24
 * describe: 初始化器,当channel注册后, 会执行里面相应的初始化方法
 */
public class HelloServerInit extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel channel) throws Exception {

       //通过socketChannel去获得相应的管道
        ChannelPipeline pipeline = channel.pipeline();

        //通关管道 添加handler 由netty自己提供的助手类 拦截器
        //当请求到服务端 需要做编解码 相应到客户端做编码
        pipeline.addLast("HttpServerCodec",new HttpServerCodec());
        //自定义的助手类
        pipeline.addLast("customHandler",new CustomHandler());

    }
}
